<?php
namespace Admin\Controller;
require_once './ThinkPHP/Library/Vendor/aliyun-oss/autoload.php';
use OSS\OssClient;
use OSS\Core\OssException;
class UploadifyController extends BaseController{
	public function aa(){
		$page=I('page');
		$action=I('action');
		$page=$page*30;
		 if($action=="yes"){
			$good_list=M('goods')->limit($page.',30')->select();
			if($good_list){
				foreach($good_list as $v){
					$dizi=$v['original_img'];
					$image = new \Think\Image();
					$image->open('.'.$dizi);
					$image->thumb(750, 750)->save('.'.$dizi);
				}
				echo \json_encode([
					"action"=>"yes"
				]);exit;
			}else{
				echo \json_encode([
					"action"=>"no"
				]);exit;
			}
			}
			$this->assign('page',$page+1);
			$this->display();
		
	}
	
	public function myoss(){
		// $pic_list=rtrim(I('pic_list'), ',');
		// $pic_list=\explode(',',$pic_list);
		
		// $accessKeyId = "LTAI4GJQeSRcVhkNL5VHvQ8a";
		// $accessKeySecret = "PFI1Ij1FWKCoHHxHv9jpbbUHriacTK";
		// $endpoint = "https://badatong168.oss-cn-guangzhou.aliyuncs.com/";
		// $bucket= "badatong168";
		
		// foreach($pic_list as $v){
		// 	//shadow code oss
		// 	$object = str_replace('/Public/', '', $v);
		// 	$filePath = '.'.$v;
		// 	$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint, true);
		// 	$ossClient->uploadFile($bucket, $object, $filePath);
		// 	echo $object.'  ';
		// }
	}
	
    public function upload(){
        $func = I('func');
        $path = I('path','temp');
        $info = array(
        	'num'=> I('num'),
            'title' => '',       	
        	'upload' =>U('Admin/Ueditor/imageUp',array('savepath'=>$path,'pictitle'=>'banner','dir'=>'images')),
            'size' => '1M',
            'type' =>'jpg,png,gif,jpeg',
            'input' => I('input'),
            'func' => empty($func) ? 'undefined' : $func,
        );
        $this->assign('info',$info);
        $this->display();
    }
	
	public function upload2(){
	    $func = I('func');
	    $path = I('path','temp');
	    $info = array(
	    	'num'=> I('num'),
	        'title' => '',       	
	    	'upload' =>U('Admin/Ueditor/imageUp2',array('savepath'=>$path,'pictitle'=>'banner','dir'=>'images')),
	        'size' => '1M',
	        'type' =>'jpg,png,gif,jpeg',
	        'input' => I('input'),
	        'func' => empty($func) ? 'undefined' : $func,
	    );

	    $this->assign('info',$info);
	    $this->display();
	}
    
    /*
              删除上传的图片
     */
    public function delupload(){
        $action=isset($_POST['action']) ? $_POST['action'] : null;
        $filename= isset($_POST['filename']) ? $_POST['filename'] : null;
        $filename= str_replace('../','',$filename);
        $filename= trim($filename,'.');
        $filename= trim($filename,'/');
        if($action=='del' && !empty($filename)){
            $size = getimagesize($filename);
            $filetype = explode('/',$size['mime']);
            if($filetype[0]!='image'){
                return false;
                exit;
            }
            unlink($filename);
            exit;
        }
    }

}